Skip to content

perf: fold identical code when linking the optimized runtime - #2106

Merged
edusperoni merged 1 commit into
mainfrom
perf/app-size
Nov 11, 2026
Merged

edusperoni merged 1 commit into
mainfrom
perf/app-size

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Links the optimized runtimes (-Poptimized, -PoptimizedWithInspector) with -Wl,--icf=all, so lld folds identical functions into one copy. No V8 rebuild is needed.

libNativeScript.so, arm64 before after
optimized (what release apps ship) 27.30 MB 24.46 MB (−2.8 MB, −10%)
optimized-with-inspector 28.33 MB 25.40 MB
optimized, deflated (≈ Play download) 8.87 MiB 8.36 MiB

--icf=safe folds nothing for this build. It only folds functions whose address is known not to be taken, and V8's objects carry no address-significance tables.

With --icf=all, two identical functions can end up at the same address. Code that compares function pointers for identity would break. The full test suite doesn't show any such dependency.

Also checked: uncompressed dex. I looked at whether the app template should store classes.dex uncompressed, so the installed app doesn't keep an extracted copy. For App Bundle installs it's already uncompressed: in the device split APKs generated from a release AAB for an API 33 arm64 phone, classes.dex is stored (base-master). So this PR doesn't change the dex packaging.

Does your commit message include the wording below to reference a specific issue in this repo?

No issue.

Related Pull Requests

None.

Does your pull request have unit tests?

No new tests; this is a link flag.

  • Device suite: a debug test app on the optimized-with-inspector runtime (the ICF link only applies to optimized builds), API 36 emulator. Results are identical with and without ICF: 1551 specs, 0 failures, 7 skipped, 95 disabled. The intentional native-crash-on-alien-thread from UncaughtErrorPolicyTest appears in both.
  • Speed:
    • JNI microbenchmarks (debug.ns.jnibench, optimized release, Galaxy S20 FE, alternating builds): neutral within the phone's clock-state noise. A few rows moved ±3–10% in both directions between runs.
    • Hardware counters: two builds that differ only in this flag execute the same number of instructions for the same work: about 7.25–7.36 billion for the String-argument callback benchmark and 13.1–13.3 billion for all callback benchmarks. ICF never used more cycles.

Summary by CodeRabbit

  • Build Improvements
    • Optimized NativeScript builds now use an additional linker optimization. Non-optimized builds are unchanged.
    • This update affects how optimized builds are produced; no changes to app features or behavior are noted.

Link the optimized runtimes with -Wl,--icf=all. libNativeScript.so
(arm64) drops from 27.3 MB to 24.5 MB, and the optimized-with-inspector
one from 28.3 MB to 25.4 MB. --icf=safe folds nothing, because the V8
objects have no address-significance tables.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The optimized NativeScript build configuration adds -Wl,--icf=all to the linker flags. The non-optimized configuration is unchanged.

Changes: NativeScript Linking

Layer / File(s) Summary
Optimized link flags
test-app/runtime/CMakeLists.txt
Optimized builds now pass -Wl,--icf=all to the linker. Existing linker flags remain, and non-optimized builds are unchanged.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Refactor

Suggested reviewers: nathanwalker

Merge Risk: Minimal · up to 1ee54

The change adds a linker flag to shrink optimized builds. The author reports a full device test suite with no failures. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "perf: fold identical code when linking the optimized runtime" matches the main change. The raw summary and objectives show the PR adds -Wl,--icf=all to the linker flags for optimized Native…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf: fold identical code when linking the optimized runtime" matches the main change. The raw summary and objectives show the PR adds -Wl,--icf=all to the linker flags for optimized NativeScript runtime builds, which folds identical functions to reduce library size. The title is specific and concise, and it avoids file lists and vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 560b3bf and 1ee545e.

Files selected for processing: 1

  • test-app/runtime/CMakeLists.txt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@edusperoni
edusperoni merged commit 8fe217a into main Nov 11, 2026
8 checks passed
@edusperoni
edusperoni deleted the perf/app-size branch November 11, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant